package gappengko;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/** JSONP interface for searching a map based on a set of key-value criteria.
 * Returns a JSON array of maps
 * 
 */
public class MultipleSearchServlet extends HttpServlet {

  private static final long serialVersionUID = 1L;

  private HttpRequestHandler _handler = new HttpRequestHandler();
  
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException {
    try {
      CrossDomainUtils.enableCrossOriginResourceSharing(req, res);     
      String json = _handler.multipleSearch(req).toString();      
      ContentNegotiationUtils.processRequest(req, res, json);      
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
	}
	
	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException {
    try {
      CrossDomainUtils.enableCrossOriginResourceSharing(req, res);     
      String json = _handler.multipleSearch(req).toString();      
      ContentNegotiationUtils.processRequest(req, res, json);      
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
	}
	
	@Override
	public void doOptions(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
	  CrossDomainUtils.doOptions(req, res);
	}

}
